package com.homestead.exception;

import com.homestead.resp.CommonResponse;
import com.homestead.utils.CommonResponseUtil;
import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author HanBin_Yang
 * @since 2021/3/27 15:49
 */

@RestControllerAdvice
@Log4j2
public class AdviceController {

    @ExceptionHandler(BusinessException.class)
    public CommonResponse<Object> baseException(BusinessException e) {
        log.error("code={}, message={}, 类#方法名:{}#{}, Exception所在行:{}",e.getCode(), e.getMessage(), e.getStackTrace()[0].getClassName(), e.getStackTrace()[0].getMethodName(), e.getStackTrace()[0].getLineNumber(), e.getCause());
        return CommonResponseUtil.fail(e.getCode(), e.getMessage());
    }
}
